﻿if ($($env:APPVEYOR_REPO_BRANCH) -eq "master") {
    dotnet publish Aufo.Web -o "$($env:PublishFolder)"

    #iis自动部署脚本
    $siteName = "Aufo.Blazor.Server"
    $port = "80"
    $sourcePath= $($env:PublishFolder)
    $targetPath= $($env:SiteFolder)

    Write-Host "siteName:$siteName,port:$port"

    Import-Module WebAdministration

    #停止网站
    Write-Host "stop website"
    Stop-Website -Name $siteName

    #删除原站点文件
    Write-Host "delete website"
    del $targetPath -recurse

    #复制新站点文件到目标文件夹
    Write-Host "copy website"
    copy $sourcePath $targetPath -recurse

    #启动网站
    Write-Host "start website"
    Start-Website -Name $siteName

    Write-Host "$siteName successfully started"


    dotnet publish Aufo.Web.Mobile -o "$($env:MobilePublishFolder)"

    $siteName = "Aufo.Blazor.Mobile"
    $port = "80"
    $sourcePath= $($env:MobilePublishFolder)
    $targetPath= $($env:MobileSiteFolder)

    Write-Host "siteName:$siteName,port:$port"

    Write-Host "stop website"
    Stop-Website -Name $siteName

    Write-Host "delete website"
    del $targetPath -recurse

    Write-Host "copy website"
    copy $sourcePath $targetPath -recurse

    Write-Host "start website"
    Start-Website -Name $siteName

    Write-Host "$siteName successfully started"
}